package com.example.javademo.easy;

import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.time.Duration;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by xuguangyuansh on 2018/12/25.
 */
@RestController
public class UserController {

    @GetMapping("/user")
    public Mono<Map<String, String>> hello() {
        Map<String, String> map = new HashMap<String, String>();
        map.put("1", "lily");
        return Mono.just(map).delayElement(Duration.ofMillis(2000)); // 2s
    }

    @PostMapping("/add")
    public Mono<Integer> add(int a) {
        return Mono.just(++a);
    }

    @PutMapping("/put")
    public Mono<Integer> put(int a) {
        return Mono.just(++a);
    }

    /**
     * /delete/3
     *
     * @param a
     * @return
     */
    @DeleteMapping("/delete/{c}")
    public Mono<Integer> delete(@PathVariable("c") int a) {
        return Mono.just(++a);
    }
}
